﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
    CodeFile="Custom_Add.aspx.cs" Inherits="Admin_Custom_Add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        var isDialogPage = (frameElement!= null);//本页面是否是对话框打开的

        if (isDialogPage) {
            
            // api.opener 为载加lhgdialog.min.js文件的页面的window对象
            // D 为载加lhgdialog.min.js文件的页面的document对象
            //不是lhgdialog打开
            if (typeof (frameElement.api) == "undefined") {
                isDialogPage = false;
            } else {
                var api = frameElement.api, W = api.opener, D = W.document;
            }
        }

        $(function () {

            dark.form({
                appendTo: $(".form2"),
                title: "添加客户资料",
                data: {},
                width: 430,
                items: [
				{ id: "DisplayName", label: "客户昵称", type: "textbox", width: 180 },
                { id: "CustomEmail", label: "Email", type: "textbox", required: true, width: 180 },
                { id: "MobilePhone", label: "手机号码", type: "textbox", required: true, width: 180 },

                { id: "submit", label: "添加", type: "submit", iconCls: "icon-save", url: "",
                    onClick: function (isValid, formData) {
                        dark.dialog.loading("正在验证客户资料...");
                        var isExist = DarkCRM.Models.Custom.CheckCustomExist(formData).ErrorCode > 0;
                        if (isExist) {
                            dark.dialog.closeLoading();
                            dark.dialog.error("对不起，该客户已经存在!");
                        } else {
                            dark.dialog.loading("正在保存客户资料...");
                            DarkCRM.Models.Custom.Create(formData, { success: function (result) {
                                dark.dialog.closeLoading();
                                if (result.ErrorCode == 0) {
                                    dark.dialog.successAlter("添加成功!", function () {
                                        if (isDialogPage) {
                                            W.reload(); //刷新parent的grid控件
                                            api.close(); //关闭自己对话框
                                        }
                                    });
                                } else {
                                    dark.dialog.error("对不起，添加失败!");
                                }
                            }
                            });
                        }
                    },
                    success: function (isValid, data) {

                    },
                    onLoadError: function () {
                    }
                }
                ]
            });
        });

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="form2">
    </div>
</asp:Content>
